<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\CustHub\Constants\RoomInviteSendTaskStatusConstants;
use App\CustHub\Model\ChRoomInviteSendTask;
use Hyperf\Database\Model\Collection;
use Mine\Abstracts\AbstractMapper;

class ChRoomInviteSendTaskMapper extends AbstractMapper
{
    public function assignModel()
    {
        $this->model = ChRoomInviteSendTask::class;
    }

    /**
     * 获取待重发任务
     * @param string $roomWxid
     * @param array $userId
     * @return bool
     */
    public function checkReSendTaskExistence(string $roomWxid,array $userId): bool
    {
        return $this->model::query()
            ->whereIn('user_id',$userId)
            ->where('room_wxid',$roomWxid)
            ->where('status',RoomInviteSendTaskStatusConstants::WAITING)
            ->where('type',0)
            ->exists();
    }

    /**
     * 获取营销信息
     * @param string $roomWxid
     * @param array $userId
     * @return array|Collection|\Hyperf\Collection\Collection
     */
    public function getMarketingMessages(string $roomWxid,array $userId): array|Collection|\Hyperf\Collection\Collection
    {
        return $this->model::query()
            ->whereIn('user_id',$userId)
            ->where('room_wxid',$roomWxid)
            ->where('status',RoomInviteSendTaskStatusConstants::WAITING)
            ->where('type',1)
            ->get();
    }
}